import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = { //要设置的全局访问的state对象
    theme: "light",
    valueNumber: 1, //要设置的初始属性值
    list: [{
        id: 1,
        name: 'zs'
    }, {
        id: 2,
        name: 'ls'
    }, {
        id: 3,
        name: 'ww'
    }, {
        id: 4,
        name: 'xl'
    }, {
        id: 5,
        name: 'xm'
    }],
    inputValue: '',
    i: 0,
    text: ''
};

const getters = {
    getActions(state) {
        return state.text;
    }
};

const mutations = {
    changeTheme(state, theme) {
        //自定义改变state初始值的方法，这里面的参数除了state之外还可以再传额外的参数(变量或对象);
        state.theme = theme;
    },
    inputValue(state, inputValue) {
        state.i = state.i + 1;
        state.inputValue = `在mutations中对输入框的值进行第${state.i}次操作`;
        state.inputValue = state.inputValue + inputValue;
        return state.inputValue;
    },
    useActions(state, actionsValue) {
        return state.text = actionsValue;
    }
};
const actions = {
    useActions(context, actionsValue) {
        //自定义改变state初始值的方法，这里面的参数除了state之外还可以再传额外的参数(变量或对象);
        return context.commit('useActions', actionsValue);
    }
};
const store = new Vuex.Store({
    state,
    getters,
    mutations,
    actions,
});

export default store;